package com.google.code.drift.utils;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;

public class ImageUtils {

	/**
	 * 根据传入的Bitmap，生成圆角+黑边的Bitmap并返回
	 * 
	 * @param inputBitmap
	 * @return
	 */
	public static Bitmap getRoundedCornerBitmap(Bitmap inputBitmap) {

		int width = inputBitmap.getWidth();
		int height = inputBitmap.getHeight();
		Bitmap outputBitmap = Bitmap.createBitmap(width, height,
				Config.ARGB_8888);
		Canvas canvas = new Canvas(outputBitmap);

		Paint paint = new Paint();
		paint.setAntiAlias(true);
		paint.setColor(0xffC1C6F4);// 浅蓝
		Rect rect = new Rect(1, 1, width - 1, height - 1);
		RectF rectF = new RectF(rect);

		// 绘制圆角
		float roundPx = (float) (width * 0.08);
		canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
		paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
		canvas.drawBitmap(inputBitmap, rect, rect, paint);

		// 绘制黑边
		paint.setXfermode(new PorterDuffXfermode(Mode.DST_OVER));
		RectF rectF2 = new RectF(0.7f, 0.7f, (float) (width - 0.7),
				(float) (height - 0.7));
		paint.setColor(0xff000000);// 黑色
		float roundPx2 = (float) (width * 0.09);
		canvas.drawRoundRect(rectF2, roundPx2, roundPx2, paint);

		return outputBitmap;

	}

}
